package cn.com.hhrcw.vo;

import cn.com.hhrcw.entity.SysLog;
import cn.com.hhrcw.utils.DateUtil;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @program: recruit-boot-parent
 *
 * @author: JD
 * @create: 2020-11-13 10:46
 **/
@Data
public class SevenDayInfoVO {

    /**
     * 近七天活跃数量
     */
    Map<Integer, Integer> sevenMap;

    List<String> sevenList;

    public void doSevenDays(List<SysLog> histories) {
        sevenList = DateUtil.getDaysBetwwen(6);
        if (!CollectionUtils.isEmpty(histories)) {
            Set<SysLog> result = new HashSet(histories);
            sevenMap = new LinkedHashMap<>();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            int a = 6;
            for (int i = 0; i <= a; i++) {
                String time = DateUtil.getDayString(i);
                Integer count = sevenMap.get(i) == null ? 0 : sevenMap.get(i);
                try {
                    long statMil = format.parse(time).getTime();
                    long endMil = statMil + 86400000;
                    for (cn.com.hhrcw.entity.SysLog e : result) {
                        if (e.getCreateTime().getTime() >= statMil && e.getCreateTime().getTime() < endMil) {
                            count = count + 1;
                        }
                    }
                    sevenMap.put(i, count);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
